package cn.itcast.service.cargo.impl;

import cn.itcast.dao.cargo.PackingListDao;
import cn.itcast.domain.cargo.PackingList;
import cn.itcast.domain.cargo.PackingListExample;
import cn.itcast.service.cargo.PackingListService;
import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@Service
public class PackingListServiceImpl implements PackingListService {

    @Autowired
    private PackingListDao packingListDao;

    //分页
    @Override
    public PageInfo<PackingList> findByPage(PackingListExample packingListExample, int pageNum, int pageSize) {
        //1. 设置开始页与页面大小
        PageHelper.startPage(pageNum, pageSize);
        //2. 设置所有
        List<PackingList> list = packingListDao.selectByExample(packingListExample);
        //3 /.构建一个PageInfo
        PageInfo<PackingList> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    //查找全部
    @Override
    public List<PackingList> findAll(PackingListExample packingListExample) {

        return packingListDao.selectByExample(packingListExample);
    }

    //找单个
    @Override
    public PackingList findById(String id) {

        return packingListDao.selectByPrimaryKey(id);
    }

    //新增
    @Override
    public void save(PackingList packingList) {
        packingListDao.insert(packingList);

    }

    //修改
    @Override
    public void update(PackingList packingList) {
        packingListDao.updateByPrimaryKeySelective(packingList);
    }

    //删除
    @Override
    public void delete(String id) {
        packingListDao.deleteByPrimaryKey(id);
    }
}
